<template>
	<view>
		<uni-section title="相册介绍" type="line">
			<uni-notice-bar :text="photodetail.content" />
		</uni-section>
		<uni-section title="相册图片" type="line">
		</uni-section>
		<view v-for="i in photodetail.img">
			<image style="width: 100%;" :src=i></image>
		</view>
		<!-- 评论区 -->
		<uni-section title="评论区" type="line">
		</uni-section>
		<view style="background-color: gray;">
			<qizai9527-commentList :photoId="photoId" :parentId="parentId" :list="commentList" @sureadd="sureadd"
				@del="del">
			</qizai9527-commentList>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				//相册ID
				photoId: 0,
				//家长ID
				parentId: 1,
				//评论列表
				commentList: [],
				//相册详情
				photodetail: {}
			}
		},
		onLoad(photoId) {
			this.photoId = photoId.photoId
			this.$myReq({
				url: '/photo/api/alldiscuss/' + this.photoId,
				method: "get",
			}).then(r => {
				this.commentList = r.data
				console.log(this.commentList);
			})
		},
		onShow() {
			this.$myReq({
				url: '/photo/api/detail/' + this.photoId,
				method: "get",
			}).then(r => {
				this.photodetail = r.data
				console.log(r.data);
			})
		},
		methods: {
			//删除评论
			del(e) {
				this.$myReq({
					url: '/photo/api/deleteDiscuss/' + e.id + '/' + e.photoId,
					method: "delete",
					//date:e.id,
				}).then(r => {
					this.commentList.splice(e.index, 1)
				})
			},
			//确认评论
			sureadd(e) {
				if (e.content == null || e.content == "") {
					return;
				} else {
					e.senderId = this.parentId
					this.$myReq({
						url: '/photo/api/adddiscuss',
						method: "POST",
						data: e,
					}).then(r => {
						this.commentList.push(r.data)
						console.log(r.data);
					})
				}
			},
		}
	}
</script>

<style>
</style>
